<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>用户注册</title>
<link href="/theme/default/css.css" type="text/css" rel="stylesheet"/>
<!-- 载入Jquery框架 -->
<script src="/js/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="/js/common.js" type="text/javascript"></script>
<script>var fields = Array('username', 'password', 'confirm', 'email');</script>
<!-- 载入Jquery消息提示框架 -->
<script src="/js/lhgdialog/lhgdialog.min.js" type="text/javascript"></script>
<!-- 载入Jquery表单插件 -->
<script src="/js/jquery.form.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	/*$("#username").blur(function(){
		if ($("#username").val().length < 3 || $("#username").val().length >15 ) {
			$.dialog.tips('昵称需要3-15个字符'); 
		} else {
			$.getJSON("{#spUrl c=user a=checkname}", { 'username': $('#username').val() }, function(json){
				if (json.status == false) {
					$.dialog.tips(json.message); 
				}
			}); 
		}
	});*/
	
	$("#email").blur(function(){
		if (!$("#email").val().match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) {
			$.dialog.tips('邮箱格式不正确！'); 
		} else {
			$.getJSON("{#spUrl c=user a=checkemail}", { 'email': $('#email').val() }, function(json){
				if (json.status == false) {
					$.dialog.tips(json.message); 
				}
			}); 
		}
	});
			
	//设置Ajax属性
	var options = { 
		target: null, 
		type: "post",
		dataType: "json",
		beforeSubmit: checkform,
		url: '{#spUrl c=user a=reg}', 
		success: function(json){
			if (json.status == false) {
				$.dialog.tips(json.message); 
				setTimeout("location='{#spUrl c=user a=reg}'",500); 
			}
			if (json.status == true) {
				$.dialog.tips(json.message); 
				setTimeout("location='{#spUrl c=user a=login}'",500); 
			}
		},
	};
	$('#form1').ajaxForm(options);
	
	//表单验证函数
	function checkform(){
		//验证用户名
		if ($("#username").val().length < 3 || $("#username").val().length >15 ) {
			$.dialog.tips('昵称需要3-15个字符');
			return false;	
		}
		
		//验证密码
		if ($("#password").val().length < 6 || $("#password").val().length >30 ) {
			$.dialog.tips('密码最少6个字符');
			return false;	
		}

		//验证确认密码
		if ($("#password").val() != $("#confirm").val()) {
			$.dialog.tips('密码不一致');
			return false;	
		}
		
		//验证密码
		if (!$("#email").val().match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) {
			$.dialog.tips('邮箱格式不正确！'); 
			return false;	
		}
		
		$("#submit").attr("value", "注册中...");
		$("#submit").attr("disabled", true);
		return true;
	}
});
</script>
</head>

<body>
{#include file='header.html'}
<form id="form1" name="form1" method="post" action="{#spUrl c=user a=reg}">
    <div class="reg">
        <h2>注册</h2>
        <ul>
        <li><input name="username" type="text" id="username" size="20" class="input" title="昵称，3-15个字符" /><label id="username-tip" class="tip" for="username"></label></li>
        <li><input name="password" type="password" id="password" size="20" class="input" title="密码，最少6个字符" /><label id="password-tip" class="tip" for="password"></label></li>
        <li><input name="confirm" type="password" id="confirm" size="20" class="input" title="确认密码，与密码保持一致哦" /><label id="confirm-tip" class="tip" for="confirm"></label></li>
        <li><input name="email" type="text" id="email" size="20" class="input" title="电子邮箱，最好是常用邮箱"/><label id="email-tip" class="tip" for="email"></label></li></ul>
        <div align="right"><input type="submit" name="submit" id="submit" value="注册" /></div>
    </div>
</form>
</body>
</html>
